package msc.dodo.wtb.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import msc.dodo.wtb.request.ReqSuperDto;
import msc.dodo.wtb.response.RespDto;
import msc.dodo.wtb.util.HttpUtil;
import org.springframework.http.MediaType;

public class SendDoDoApi implements DoDoApi{

    @Override
    public RespDto sendToDoDo(ApiInfoList apiInfoList, ReqSuperDto reqSuperDto) {
        RespDto respDto = null;
        //根据传输数据类型做一些数据格式传化的动作
        if(apiInfoList.getMediaType().equals(MediaType.APPLICATION_JSON_VALUE)){
            JSONObject body = JSON.parseObject(JSON.toJSONString(reqSuperDto));
            respDto = HttpUtil.sendJsonByHTTP(body, apiInfoList);
        }else if(apiInfoList.getMediaType().equals(MediaType.MULTIPART_FORM_DATA_VALUE)){
            respDto = HttpUtil.sendByteByHTTP(reqSuperDto.getFile(), apiInfoList);
        }
        return respDto;
    }
}
